import 'dart:math';

/**
 * 功能组件篇
 *
 * 这里有  导航返回拦截
 * 数据共享
 * 跨组件数据共享
 * 异步UI更新
 * 对话框详解
 */
import 'package:flutter/material.dart';

import 'MConstant.dart';

class FunctionDemo extends StatefulWidget {
  @override
  _FunctionDemo createState() => new _FunctionDemo();
}

class _FunctionDemo extends State<FunctionDemo> {
  /*
   * 创建路由集合集合
   * Key为路由路径
   * value为文本
   */
  var routesMap = MConstant.getFunctionRoutesName();

  var colorList = [
    Colors.greenAccent,
    Colors.green,
    Colors.blue,
    Colors.red,
    Colors.amber,
    Colors.black54,
    Colors.deepPurple,
    Colors.pink
  ];
  var random = new Random();

  @override
  Widget build(BuildContext context) {
    return ListView.builder(
        itemBuilder: (context, index) {
          return Padding(
            padding: EdgeInsets.fromLTRB(12.0, 0, 12.0, 0),
            child: RaisedButton(
              onPressed: () {
                Navigator.pushNamed(context, routesMap.keys.toList()[index]);
              },
              child: Text(routesMap.values.toList()[index],
                  style: TextStyle(color: Colors.white, fontSize: 14.0)),
              shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(25)),
              elevation: 2.0,
              highlightElevation: 8.0,
              disabledElevation: 0.0,
              color: colorList[random.nextInt(colorList.length)],
            ),
          );
        },
        itemCount: routesMap.length);
  }
}
